<template>
  <a-spin :spinning="confirmLoading">
    <a-form-model ref="form" :model="models" :rules="validatorRules">
      <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="content" required label="选择内容">
        <a-radio-group name="tenantStatus" v-model="model.content">
          <a-radio value="标题">标题</a-radio>
          <a-radio value="摘要">摘要</a-radio>
          <a-radio value="序言">序言</a-radio>
          <a-radio value="大纲">大纲</a-radio>
          <a-radio value="参考文献">参考文献</a-radio>
        </a-radio-group>
      </a-form-model-item>
      <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="language" required label="选择语言">
        <a-radio-group name="tenantStatus" v-model="model.language">
          <a-radio value="中文">中文</a-radio>
          <a-radio value="英文">英文</a-radio>
        </a-radio-group>
      </a-form-model-item>
      <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="major" required label="专业">
        <a-textarea
          :rows="3"
          v-model="models.major"
          placeholder="请输入专业名称，比如拿想要内容为论文题目举例：环境工程"
        />
      </a-form-model-item>
      <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="topic" required label="论文题目">
        <a-textarea
          :rows="5"
          v-model="models.topic"
          placeholder="您可以选择想要内容为：大纲、摘要、序言、正文、参考文献时填写论文题目"
        />
      </a-form-model-item>
      <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="keyword" required label="关键词">
        <a-textarea
          :rows="5"
          v-model="models.keyword"
          placeholder="请输入想要的内容的关键词，比如拿想要内容为论文题目举例：污水处理厂淤泥；重金属吸附；植物"
        />
      </a-form-model-item>
      <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wordNumber" required label="字数要求">
        <a-input-number placeholder="请输入字数(<=350)" v-model="model.wordNumber" />
      </a-form-model-item>
    </a-form-model>
  </a-spin>
</template>

<script>
export default {
  name: 'AcademicArticles',
  components: {},
  props: {
    model: {
      type: Object,
      default: {},
    },
  },

  data() {
    return {
      addIconShow: true,
      shoppIngIcon: '',
      models: this.model,
      confirmLoading: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 12 },
      },
      validatorRules: {
        major: [
          { required: true, message: '请输入专业' },
          { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' },
        ],
        topic: [
          { required: true, message: '请输入论文题目' },
          { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' },
        ],
        keyword: [
          { required: true, message: '请输入关键词' },
          { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' },
        ],
      },
    }
  },

  created() {},
  computed: {
    models1() {
      return this.models
    },
  },
  watch: {
    models1: {
      handler(newVal, oldVal) {
        // console.log('newVal + oldVal',newVal, oldVal)
        // console.log('handler',newVal,  this.model)
        if (!newVal.content) {
          //只需判断一个即可
          this.$set(this.model, "content", "标题");
          this.$set(this.model, "language", "中文");
          this.$set(this.model, "wordNumber", "350");
        }
      },
      deep: true,
      immediate: true,
    },
  },
  updated() {},
  mounted() {
    this.$nextTick(function () {
      console.log('11111111111111111', this.models)
    })
  },
  methods: {
    generatedBtnProp() {
      let obj = {
        content: this.models.content,
        language: this.models.language,
        major: this.models.major,
        topic: this.models.topic,
        keyword: this.models.keyword,
        wordNumber: this.models.wordNumber,
      }
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$emit('appApiAsk', 1, obj)
        } else {
          this.$emit('appApiAsk', 2, obj)
        }
      })
    },
  },
}
</script>

<style lang="less">
</style>